Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = void 0;

var _user = _interopRequireDefault(require("../../public/utils/user")), _promise = _interopRequireDefault(require("../../public/utils/promise")), _request = require("../../public/utils/request");

function _interopRequireDefault(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

var ImageManager = {
    uploadImage: function(i, n) {
        var t = !(2 < arguments.length && void 0 !== arguments[2]) || arguments[2], o = n.length, l = _user.default.getTokensSync().accesstoken;
        return new _promise.default(function(a, e) {
            if (n && o) {
                t && wx.showLoading({
                    title: "上传图片中..."
                });
                var u = [], r = 0;
                !function t(e) {
                    (0, _request.upload)({
                        url: "".concat(i, "?accesstoken=").concat(l),
                        name: "image",
                        filePath: e,
                        formData: {
                            cardid: getApp().globalData.card.cardid,
                            type: "image"
                        }
                    }).catch(function() {
                        return {};
                    }).then(function(e) {
                        r++, 0 === e.code && u.push({
                            fieldid: e.data.id,
                            url: e.data.url
                        }), r === o ? (a(u), wx.hideLoading()) : t(n[r]);
                    });
                }(n[r]);
            } else e("文件路径错误");
        });
    }
}, _default = ImageManager;

exports.default = _default;